package com.shrikanthravi.customnavigationdrawer.fraction;

import com.shrikanthravi.customnavigationdrawer.ResourceTable;
import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;
import ohos.app.Context;

public class NewsFraction extends Fraction {
    private String mTitle;
    private int color;
    private static Context mContext;

    public static NewsFraction getInstance(Context context, String title, int color) {
        NewsFraction sf = new NewsFraction();
        sf.mTitle = title;
        sf.color = color;
        mContext=context;
        return sf;
    }

    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component component = scatter.parse(ResourceTable.Layout_fr_news_main, container, false);
        Text text = (Text) component.findComponentById(ResourceTable.Id_card_title_tv);
        DependentLayout dependentLayout = (DependentLayout) component.findComponentById(ResourceTable.Id_dependLayout);
        text.setText(mTitle);
        ShapeElement element = new ShapeElement();
        element.setRgbColor(RgbColor.fromArgbInt(mContext.getColor(color)));
        dependentLayout.setBackground(element);
        return component;
    }
}
